//
//  EquipmentDetailController.m
//  PropertyMananger
//
//  Created by bh on 17/2/8.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "EquipmentDetailController.h"
#import "EquipmentDetailCell.h"

@interface EquipmentDetailController ()
/**标题数据源**/
@property (nonatomic,strong) NSArray * mTitleArr;
/**信息详细数据源**/
@property (nonatomic,strong) NSArray * mInfoArr;
@end

@implementation EquipmentDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTitleViewName:@"设备查询详情"];
    
    [self initTableViewWithView:self.view frame:CGRectMake(0, 0, BHscreenW, BHscreenH - 64) isGroup:NO];
    self.tableView.backgroundColor = BHGrayColor;
    
    [self initData];
}
#pragma makr - 数据源
- (void)initData
{
    //标题
    self.mTitleArr = @[@"设备编号:",@"设备名称:",@"规格型号:",@"设备状态:",@"设备类别:",@"安装地址:",@"安装时间:"];
    //信息
  //  self.mInfoArr = @[@"2016343543",@"监控摄像头",@"WFH-54544",@"在用",@"监控",@"1栋2单元6层楼梯间",@"2017-04-03"];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.mTitleArr.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    EquipmentDetailCell * cell = [EquipmentDetailCell cellWithTableView:tableView];
    cell.nameLabel.text = self.mTitleArr[indexPath.row];

    if (indexPath.row == 0) {
        
        cell.titleLabel.text = self.model.EquipmentNumber;
        
    }else if (indexPath.row == 1){
        
        cell.titleLabel.text = self.model.EquipmentName;
        
    }else if (indexPath.row == 2){
        
        cell.titleLabel.text = self.model.SpecificationModel;
        
    }else if (indexPath.row == 3){
        
        cell.titleLabel.textColor = [UIColor redColor];
        cell.titleLabel.text = self.model.EquipmentManagementStateItemName;
        
    }else if (indexPath.row == 4){
        
        cell.titleLabel.text = self.model.EquipmentCategoryItemName;
        
    }else if (indexPath.row == 5){
        
        cell.titleLabel.text = self.model.InstallationAddress;
        
    }else if (indexPath.row == 6){
        
        cell.titleLabel.text = self.model.InstallDate;
    }
    
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 45;
    
}
#pragma mark - 搜索代理方法
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    
    if (searchText.length == 0) {
        self.searchText = @"";
        self.isSearch = NO;
        
        [self.tableView reloadData];
        self.placehoderImg.hidden = NO;
        self.titleLabel.hidden = NO;
        
    }
    
    
    self.searchText = searchText;
    NSLog(@" --- %@",self.searchText);
    self.searchStr = searchText;
    
    [self.resultArr removeAllObjects];
    
    
    
    if (self.resultArr.count) {
        
        self.isSearch = YES;
        self.placehoderImg.hidden = YES;
        self.titleLabel.hidden = YES;
        
        [self.tableView reloadData];
    }
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    
    //数据请求
    //   [self postHouseQueryData];
    
}
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    
    return YES;
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    self.isSearch = NO;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
    [self.view resignFirstResponder];
    [self.tableView endEditing:YES];
    self.isSearch = NO;
    
}
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    
    DLog(@"--------%zd--------%zd",range.length,range.location);
    if (range.location == 0) {
        
        
        
        self.placehoderImg.hidden = NO;
        self.placehoderImg.hidden = NO;
    }
    
    return YES;
}


@end
